<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

</body>
<script type="text/javascript"
	src="https://code.jquery.com/jquery-3.3.1.js"></script>

<script type="text/javascript">
	//获取新歌榜top100并添加数据到music表单
	function getTop100() {
		$.ajax({
			"url" : "http://192.168.11.240:3000/top/list?",
			"type" : "get",
			"data" : {
				"idx" : "0"
			},
			"success" : function(data) {
				var tracks = data.playlist.tracks;
				for (var i = 0; i < 100; i++) {
					var obj = tracks[i];
					var mname = obj.name;
					//var murl = getMusicUrl(i, obj.id);
					$.ajax({
						"url" : "ms.do?ac=add",
						"data" : {
							"mname" : mname,
							"murl" : obj.id
						},
						"success" : function(data) {
							console.log(data.msg);
						}
					});
				}
			}
		});
	};

	function getMusicUrl(i, MusicId) {
		$.ajax({
			"async" : false,
			"url" : "http://192.168.11.240:3000/song/url",
			"type" : "get",
			"data" : {
				"id" : MusicId
			},
			"success" : function(data) {
				var songInfo = data.data[0];
				url = songInfo.url;
			}
		});
		return url;
	};

	getTop100();
</script>
</html>